
# Honor the DESTDIR env variable:
if (DEFINED ENV{DESTDIR})
    message(STATUS "DESTDIR: $ENV{DESTDIR}")
    set(INSTALL_ROOT_DIR $ENV{DESTDIR}/@CMAKE_INSTALL_PREFIX@)
else()
    set(INSTALL_ROOT_DIR @PYTHON_INSTALL_DIRECTORY@)
endif()

set(cmd_
    @Python3_EXECUTABLE@ -m pip install .
        --target=${INSTALL_ROOT_DIR}/@PYTHON_INSTALL_DIR@
        --ignore-installed
)

string(REPLACE ";" " " _cmd_print "${cmd_}")
message(STATUS "Running: ${_cmd_print}")

execute_process(COMMAND ${cmd_}
    RESULT_VARIABLE result
    WORKING_DIRECTORY @MRPT_PYTHON_BUILD_DIRECTORY@
)

if(result)
    message(FATAL_ERROR "CMake step for installing python modules failed: ${result}")
endif()

